package com.kinyx.framework.db.sentence.res;

import org.junit.Test;

import com.kinyx.framework.db.sentence.LikeType;

public class _Expression_LIKE_Tester_ extends SUPER {

	public void test(final boolean flag, final String tableAlias, final int tableIdx, final Column column, final String columnName, final String fieldName, final String param) {
		{
			final _Expression expression = new _Expression_LIKE(column.idx(tableIdx), flag, LikeType.LEFT, param);

			final String sentence1 = columnName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence2 = fieldName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence3 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence1;
			final String sentence4 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence2;

			this.test_getSentence(expression, //
					sentence1, //
					sentence2, //
					sentence3, //
					sentence4 //
			);
			this.test_toString(expression, //
					"SQL: [" + sentence1 + "], param: [" + "%" + param + "" + "]", //
					"HQL: [" + sentence2 + "], param: [" + "%" + param + "" + "]", //
					"SQL: [" + sentence3 + "], param: [" + "%" + param + "" + "]", //
					"HQL: [" + sentence4 + "], param: [" + "%" + param + "" + "]" //
			);
		}

		{
			final _Expression expression = new _Expression_LIKE(column.idx(tableIdx), flag, LikeType.RIGHT, param);

			final String sentence1 = columnName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence2 = fieldName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence3 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence1;
			final String sentence4 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence2;

			this.test_getSentence(expression, //
					sentence1, //
					sentence2, //
					sentence3, //
					sentence4 //
			);
			this.test_toString(expression, //
					"SQL: [" + sentence1 + "], param: [" + "" + param + "%" + "]", //
					"HQL: [" + sentence2 + "], param: [" + "" + param + "%" + "]", //
					"SQL: [" + sentence3 + "], param: [" + "" + param + "%" + "]", //
					"HQL: [" + sentence4 + "], param: [" + "" + param + "%" + "]" //
			);
		}

		{
			final _Expression expression = new _Expression_LIKE(column.idx(tableIdx), flag, LikeType.ALL, param);

			final String sentence1 = columnName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence2 = fieldName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence3 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence1;
			final String sentence4 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence2;

			this.test_getSentence(expression, //
					sentence1, //
					sentence2, //
					sentence3, //
					sentence4 //
			);
			this.test_toString(expression, //
					"SQL: [" + sentence1 + "], param: [" + "%" + param + "%" + "]", //
					"HQL: [" + sentence2 + "], param: [" + "%" + param + "%" + "]", //
					"SQL: [" + sentence3 + "], param: [" + "%" + param + "%" + "]", //
					"HQL: [" + sentence4 + "], param: [" + "%" + param + "%" + "]" //
			);
		}

		{
			final _Expression expression = new _Expression_LIKE(column.idx(tableIdx), flag, LikeType.NONE, param);

			final String sentence1 = columnName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence2 = fieldName + " " + (flag ? "LIKE" : "NOT LIKE") + " ?";
			final String sentence3 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence1;
			final String sentence4 = tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + sentence2;

			this.test_getSentence(expression, //
					sentence1, //
					sentence2, //
					sentence3, //
					sentence4 //
			);
			this.test_toString(expression, //
					"SQL: [" + sentence1 + "], param: [" + param + "]", //
					"HQL: [" + sentence2 + "], param: [" + param + "]", //
					"SQL: [" + sentence3 + "], param: [" + param + "]", //
					"HQL: [" + sentence4 + "], param: [" + param + "]" //
			);
		}
	}

	@Test
	public void test() {
		this.list_flag.forEach(flag -> {
			this.list_tableIdx.forEach(tableIdx -> {
				this.list_column.forEach(column -> {
					this.list_param.forEach(param -> {
						this.test(flag, "demoEntity", tableIdx, column.column, column.columnName, column.fieldName, param);
					});
				});
			});
		});
	}

}
